#include "CAnimation.h"

CAnimation::CAnimation()
{
	m_nCurrentFrame = 0;
	m_nMaxFrames = 0;
	m_nFrameIncrement = 1;

	m_nFrameRate = 100;
	m_lOldTime = 0;
	m_bOscillate = true;
}
void CAnimation::OnAnimate()
{
	if(m_lOldTime + m_nFrameRate > SDL_GetTicks())
	{
		return;
	}

	m_lOldTime = SDL_GetTicks();
	m_nCurrentFrame += m_nFrameIncrement;

	if(m_bOscillate)
	{
		if(m_nFrameIncrement > 0)
		{
			if(m_nCurrentFrame >= m_nMaxFrames)
			{
				m_nFrameIncrement = -m_nFrameIncrement;
			}
		}
		else if(m_nCurrentFrame <= 0)
		{
			m_nFrameIncrement = -m_nFrameIncrement;
		}
		if(m_nCurrentFrame >= m_nMaxFrames)
		{
			m_nCurrentFrame = 0;
		}
	}
}
void CAnimation::SetFrameRate(int Rate)
{
	m_nFrameRate = Rate;
}
void CAnimation::SetCurrentFrame(int Frame)
{
	if(Frame < 0 || Frame >= m_nMaxFrames)
	{
		return;
	}
	m_nCurrentFrame = Frame;
}
int CAnimation::GetCurrentFrame()
{
	return m_nCurrentFrame;
}